package com.dg11185.nearshop.view.xlistview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public abstract class IXListViewHeader extends LinearLayout{

    public final static int STATE_NORMAL = 0;

    public final static int STATE_READY = 1;

    public final static int STATE_REFRESHING = 2;

    public final static int STATE_REFRESH_OVER = 3;

    protected int mState = STATE_NORMAL;
    
    protected LinearLayout mContainer;

    public IXListViewHeader(Context context, int resourceId) {
        super(context);
        initView(context, resourceId);
    }
    
    /**
     * @param context
     * @param attrs
     */
    public IXListViewHeader(Context context, AttributeSet attrs, int resourceId) {
        super(context, attrs);
        initView(context, resourceId);

    }
    private void initView(Context context, int resourceId) {
        // 初始情况，设置下拉刷新view高度为0
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
        mContainer = (LinearLayout) LayoutInflater.from(context).inflate(resourceId, null);
        addView(mContainer, lp);
        setGravity(Gravity.BOTTOM);

    }
    
    public abstract void setState(int state);
    

    public void setVisiableHeight(int height) {
        if (height < 0)
            height = 0;
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContainer.getLayoutParams();
        lp.height = height;
        mContainer.setLayoutParams(lp);
    }

    public int getVisiableHeight() {
        return mContainer.getHeight();
    }

}
